package com.slibra.common.config;

//import com.wechat.pay.java.core.Config;
//import com.wechat.pay.java.core.RSAAutoCertificateConfig;
//import com.wechat.pay.java.core.notification.NotificationConfig;
//import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.service.partnerpayments.nativepay.NativePayService;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;
import java.math.BigDecimal;

/**
 * Properties specific to Trade.
 * <p>
 * Properties are configured in the {@code application.yml} file.
 * See {@link tech.jhipster.config.JHipsterProperties} for a good example.
 */
@Component
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {

    private final AliCloud aliCloud = new AliCloud();
    private final PlatBankAccount platBankAccount = new PlatBankAccount();
    private final QiYueSuoAccount qiYueSuoAccount = new QiYueSuoAccount();
    private final WechatPay wechatPay = new WechatPay();
    private String uploadPath;
    private String ecspUploadPath;
    private String tempPath;
    private String hostPath;
    private String bcosPath;
    private String qysCallServer;
    private BigDecimal earnestPct;
    private BigDecimal deposit;

    public String getUploadPath() {
        return uploadPath;
    }

    public void setUploadPath(String uploadPath) {
        this.uploadPath = uploadPath;
    }

    public String getEcspUploadPath() {
        return ecspUploadPath;
    }

    public void setEcspUploadPath(String ecspUploadPath) {
        this.ecspUploadPath = ecspUploadPath;
    }

    public AliCloud getAliCloud() {
        return aliCloud;
    }

    public PlatBankAccount getPlatBankAccount() {
        return platBankAccount;
    }

    public QiYueSuoAccount getQiYueSuoAccount() {
        return qiYueSuoAccount;
    }

    public String getTempPath() {
        return tempPath;
    }

    public void setTempPath(String tempPath) {
        this.tempPath = tempPath;
    }

    public String getHostPath() {
        return hostPath;
    }

    public void setHostPath(String hostPath) {
        this.hostPath = hostPath;
    }

    public String getBcosPath() {
        return bcosPath;
    }

    public void setBcosPath(String bcosPath) {
        this.bcosPath = bcosPath;
    }

    public String getQysCallServer() {
        return qysCallServer;
    }

    public void setQysCallServer(String qysCallServer) {
        this.qysCallServer = qysCallServer;
    }

    public BigDecimal getEarnestPct() {
        return earnestPct;
    }

    public void setEarnestPct(BigDecimal earnestPct) {
        this.earnestPct = earnestPct;
    }

    public BigDecimal getDeposit() {
        return deposit;
    }

    public void setDeposit(BigDecimal deposit) {
        this.deposit = deposit;
    }

    public WechatPay getWechatPay() {
        return wechatPay;
    }

    @SneakyThrows
    public NativePayService getNativePayService() {
        Config config = new RSAAutoCertificateConfig.Builder()
            .merchantId(this.wechatPay.getMerchantId())
            .privateKeyFromPath(new File(this.wechatPay.getPrivateKeyPath()).getAbsolutePath())
            .merchantSerialNumber(this.wechatPay.getMerchantSerialNumber())
            .apiV3Key(this.wechatPay.getApiV3key())
            .build();
        return new NativePayService.Builder().config(config).build();
    }

    @SneakyThrows
    public NotificationConfig getNotification() {
        return new RSAAutoCertificateConfig.Builder()
            .merchantId(this.wechatPay.getMerchantId())
            .privateKeyFromPath(new File(this.wechatPay.getPrivateKeyPath()).getAbsolutePath())
            .merchantSerialNumber(this.wechatPay.getMerchantSerialNumber())
            .apiV3Key(this.wechatPay.getApiV3key())
            .build();
    }

    @Data
    public static class AliCloud {

        private Boolean enableSms;
        private String accessKeyId;
        private String accessKeySecret;
        private String signName;
        private String templateCooperation;
        private String templateCodeMessage;
        private String templateSysRegistPassed;
        private String templateRegistPassed;
        private String templateRegistUnpassed;
        private String templateAccountFreezed;
        private String templateAccountUnfreezed;
        private String templateAccountReset;
        private String templateRegistBuyer;
    }

    @Data
    public static class PlatBankAccount {

        private Long userId;
        private String accountName;
        private String accountNumber;
        private String issuingBank;
        private String interBankNumber;
        private String issuingAddress;
    }

    @Data
    public static class QiYueSuoAccount {

        private String serverUrl;
        private String accessKey;
        private String accessSecret;
        private String secretKey;
    }

    @Data
    public static class WechatPay {

        private String merchantId;
        private String appId;
        private String privateKeyPath;
        private String merchantSerialNumber;
        private String apiV3key;
        private String orderNotifyUrl;
        private String depositNotifyUrl;
    }
}
